﻿namespace MyWebLog.Logic.Models.Security
{
    using DatabaseAbstraction.Interfaces;
    using System.Collections.Generic;
    using System.Data;

    /// <summary>
    /// This class represents a permission level within My WebLog
    /// </summary>
    public class Permission : IParameterProvider
    {
        #region Properties

        /// <summary>
        /// The ID of this permission
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// The description of this permission
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// The security level of this permission
        /// </summary>
        public int Level { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Constructor (empty object)
        /// </summary>
        public Permission() { }

        /// <summary>
        /// Constructor (filled object)
        /// </summary>
        /// <param name="reader">
        /// An open data reader, pointing to the row to use
        /// </param>
        public Permission(IDataReader reader)
        {
            ID = reader.GetInt32(reader.GetOrdinal("permission_id"));
            Description = reader.GetString(reader.GetOrdinal("permission_description"));
            Level = reader.GetInt32(reader.GetOrdinal("permission_level"));
        }

        #endregion

        #region Interface Implementation

        /// <summary>
        /// This object's properties as a dictionary, for use in persistence
        /// </summary>
        /// <returns>
        /// A key/value dictionary of the properties of this object
        /// </returns>
        public IDictionary<string, object> Parameters()
        {
            var parameters = new Dictionary<string, object>();

            parameters.Add("permission_id", ID);
            parameters.Add("permission_description", Description);
            parameters.Add("permission_level", Level);

            return parameters;
        }

        #endregion
    }
}